import {
  network
} from '../../utils/network.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    options: {},
    total: 0,
    comment: [],
    start: 1,
    count: 20,
    preLoading:false,
    nextLoading:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    let _this = this;
    _this.setData({
      options
    })
    _this.getcomments(1)

  },
  getcomments(start) {
    let _this = this;
    let id = _this.data.options.id;
    let type = _this.data.options.type;
    if(start > _this.data.start){
      _this.setData({
        nextLoading:true
      })
    }else{
      _this.setData({
        preLoading: true
      })
    }
    network.movieComments({
      type: type,
      id: id,
      start: start,
      count: 20,
      success(res) {
        let total = res.data.total;
        let comment= res.data.interests;
        _this.setData({
          comment: comment,
          total: total,
          start: start,
          preLoading:false,
          nextLoading:false
        })
        wx.pageScrollTo({
          scrollTop: 0,
        })
      }
    })
  },
  onItemTapEvent(e) {
    wx.navigateBack()
  },
  onPrePage() {
    let _this = this;
    let oldStart = _this.data.start;
    let count = _this.data.count;
    if (oldStart -count >0) {
      let start = oldStart - _this.data.count;
      this.getcomments(start)
    }
  },
  onNextPage() {
    let _this = this;
    let oldStart = _this.data.start;
    let start = oldStart + _this.data.count;
    this.getcomments(start)
  },
  onReachBottom() {
  }
})